﻿using Newtonsoft.Json;

namespace Hpt.Device.Sample.Dto
{
    public class ClientFaceSyncTaskResponse
    {
        //public ClientFaceSyncTaskReport() { }
        [JsonProperty(NullValueHandling = NullValueHandling.Include)]
        public ClientFaceSyncTaskModel[] Models { get; set; }

        public class ClientFaceSyncTaskModel
        {
            [JsonProperty(NullValueHandling = NullValueHandling.Include)]
            public int ClientID { get; set; }

            [JsonProperty(NullValueHandling = NullValueHandling.Include)]
            public ClientConnection Connection { get; set; }

            [JsonProperty(NullValueHandling = NullValueHandling.Include)]
            public AccountInfo[] AccountInfos { get; set; }

            public class ClientConnection : IEquatable<ClientConnection>
            {
                public int TerminalNo { get; set; }
                //public int ClientID { get; set; }

                public string IPAddress { get; set; }

                public int PortNumber { get; set; }

                public string Password { get; set; }

                //public string DeviceID { get; set; }
                public bool Equals(ClientConnection other)
                {
                    if (other == null) return false;
                    if (TerminalNo != other.TerminalNo) return false;
                    if (PortNumber != other.PortNumber) return false;
                    //if (Password != other.Password) return false;

                    if (string.IsNullOrWhiteSpace(IPAddress))
                    {
                        if (!string.IsNullOrWhiteSpace(other.IPAddress))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!IPAddress.Equals(other.IPAddress))
                            return false;
                    }

                    if (string.IsNullOrWhiteSpace(Password))
                    {
                        if (!string.IsNullOrWhiteSpace(other.Password))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        if (!Password.Equals(other.Password))
                            return false;
                    }

                    return true;
                }
            }

            public class AccountInfo
            {
                //public int ClientNo { get; set; }
                public int AccountID { get; set; }

                public string CardNo { get; set; }

                public string AccountName { get; set; }

                [JsonIgnore]
                public Dictionary<EnrollType, int[]> FingerData { get; set; }

                [JsonIgnore]
                public int[] FaceData { get; set; }

                public string IDentityCode { get; set; }

                public long? PhoneNumber { get; set; }

                public string AccountNo { get; set; }

                //[JsonProperty("FaceData")]
                //public byte[] FaceImage { get; set; }

                //public string FaceDataBase64 { get; set; }

                public string FaceDataUrl { get; set; }

                public SyncType SyncType { get; set; }

                public string Password { get; set; }

                public int? TwinCode { get; set; }

                public byte? IdentificationType { get; set; }
            }

            public enum SyncType
            {
                Add = 1,
                Remove = 2,
                //Update = 4
            }

            public enum EnrollType
            {
                EnrollFP1 = 0,
                EnrollFP2 = 1,
                EnrollFP3 = 2,
                EnrollFP4 = 3,
                EnrollFP5 = 4,
                EnrollFP6 = 5,
                EnrollFP7 = 6,
                EnrollFP8 = 7,
                EnrollFP9 = 8,
                EnrollFP10 = 9,
                EnrollCard = 11,

                //UserTimeZone = 14,
                Password = 15,

                //Department = 16,
                EnrollFace = 17,
            }
        }
    }
}